
# 需要在父cmake中添加链接 target_link_libraries(Framework PUBLIC stm32cubemx)

cmake_minimum_required(VERSION 3.22)

project(Framework LANGUAGES C ASM)

# 关键修改1：使用绝对路径基准
set(FRAMEWORK_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "Framework root: ${FRAMEWORK_ROOT}")

# 关键修改2：显式收集源文件
file(GLOB_RECURSE FRAMEWORK_SOURCES
        "${FRAMEWORK_ROOT}/1_Bsp/Src/*.c"
        "${FRAMEWORK_ROOT}/2_Device/Src/*.c"
        "${FRAMEWORK_ROOT}/3_Event/Src/*.c"
        "${FRAMEWORK_ROOT}/4_Cbb/Src/*.c"
        "${FRAMEWORK_ROOT}/5_OS/Src/*.c"
        "${FRAMEWORK_ROOT}/6_User/1_User_Global/Src/*.c"
        "${FRAMEWORK_ROOT}/6_User/2_User_Cfg/Src/*.c"
        "${FRAMEWORK_ROOT}/6_User/3_User_App/Src/*.c"
)


# 关键修改3：创建实体静态库
add_library(Framework STATIC ${FRAMEWORK_SOURCES})

# 关键修改4：使用PUBLIC属性传递包含路径
target_include_directories(Framework PUBLIC
        ${FRAMEWORK_ROOT}/0_Interface/Inc
        ${FRAMEWORK_ROOT}/1_Bsp/Inc
        ${FRAMEWORK_ROOT}/2_Device/Inc
        ${FRAMEWORK_ROOT}/3_Event/Inc
        ${FRAMEWORK_ROOT}/4_Cbb/Inc
        ${FRAMEWORK_ROOT}/5_OS/Inc
        ${FRAMEWORK_ROOT}/6_User/1_User_Global/Inc
        ${FRAMEWORK_ROOT}/6_User/2_User_Cfg/Inc
        ${FRAMEWORK_ROOT}/6_User/3_User_App/Inc

)

target_link_libraries(Framework PUBLIC
        ${FRAMEWORK_ROOT}/3_Event/Lib/event.lib
        ${FRAMEWORK_ROOT}/2_Device/Lib/dev_led.lib
)

# 关键修改5：同步C标准设置
set_target_properties(Framework PROPERTIES
        C_STANDARD 11
        C_STANDARD_REQUIRED ON
        C_EXTENSIONS OFF
)

set(C_STANDARD 11)
set(C_STANDARD_REQUIRED ON)
set(C_EXTENSIONS OFF)

# 验证源文件收集结果
message(STATUS "Framework sources:")
foreach(source ${FRAMEWORK_SOURCES})
    message(STATUS " - ${source}")
endforeach()

# 在文件末尾添加
add_custom_target(clean_all
        COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_DIR}/lib
        COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
)
